﻿import com.dinmax.flash.draw.control.MovieClipEvent;
import com.dinmax.flash.draw.control.MovieClipHelper;
import com.dinmax.flash.draw.control.button.*;
import com.dinmax.flash.draw.common.Point;

class PressButtonControl extends PressButton implements MovieClipEvent {
	
	private var buttonView:PressButtonView;
	private var base:MovieClip;

	function PressButtonControl(container:MovieClip, name:String, view:PressButtonView){
		super(container, name);
		if(view==undefined){
			buttonView=new PressButtonViewClassic();
		} else {
			buttonView=view;
		}
	}

	function getView():PressButtonView{
		return buttonView;
	}
	
	function disable():Void{
		getView().buttonDisable(base);
	}
	function enable():Void{
		getView().buttonNormal(base);
	}
		
	public function setSize(size:Point):Void{
		super.setSize(size);
		if(base){
			//trace("PressButtonControl.as | voy a llamar al reDraw");
			reDraw();
		}
	}
	
	function draw():Void{
		buttonView.reset();
		//Creo el movieBase
		removeMovieClip(base);
		base=createMovieClip();
		base._x=getLocation().getX();
		base._y=getLocation().getY();
		reDraw();
	}
	
	function reDraw():Void{
		//tengo que setearle propiedades porque el flash es puto
		base.width=getSize().getX();
		base.height=getSize().getY();
		
		//dibujo el borde el fondo y seteo el texto
		buttonView.border(base);
		buttonView.setText(getLabel());
		buttonView.attachImage(base, getImage());
		MovieClipHelper.setEventListener(base, this);				
			
	}

	function onPress(source:MovieClip):Void{
		getView().buttonPress(source);
		select();
	};
	function onRelease(source:MovieClip):Void{
		getView().buttonRelease(source);
	};
	function onReleaseOutside(source:MovieClip):Void{
		onRelease(source);
	};
	function onRollOut(source:MovieClip):Void{
		getView().buttonNormal(source);
	};
	function onRollOver(source:MovieClip):Void{
		getView().buttonHover(source);
	};
}